﻿using System;
using System.Collections.Generic;

using DigitalQuran.Data.Metadata;

namespace DigitalQuran.Collection
{
    /// <summary>
    /// Collection of <see cref="DigitalQuran.Part"/>
    /// </summary>
    public class PartCollection : ReadOnlyCollection<Part>
    {
        /// <summary>
        /// Total Parts in Qur'an
        /// </summary>
        public const int TotalParts = 30;

        internal PartCollection() : base(TotalParts) { }

        public override Part this[int index]
        {
            get { return _Parts[index]; }
        }

        public override IEnumerator<Part> GetEnumerator()
        {
            foreach (var item in _Parts)
            {
                yield return item;
            }
        }

        static Part[] _Parts = new Part[TotalParts];
        internal static void LoadData(IEnumerator<PartMeta> e)
        {
            for (int i = 0; i < TotalParts; i++)
            {
                e.MoveNext();
                _Parts[i] = new Part(i, e.Current);
            }
        }
    }
}